import specialModel from '../api/special';
export default Behavior({
  behaviors: [],
  properties: {},
  data: {},
  attached: function () {

  },
  methods: {
    // 加载列表数据
    realLoadData(event) {
      let { initPage, curTabIndex, initPageSize, activeTab } = event.detail
      specialModel[this.data.requestListName](activeTab.page)
        .then(({ data: curData, count }) => {
          let { dataLists } = activeTab
          let pageCount = Math.ceil(count / initPageSize) // 总页数
          // 关闭首次加载loading
          activeTab.isLoaded = true
          // 若为首页则直接替换
          activeTab.dataLists = activeTab.page === initPage ? curData : dataLists.concat(curData)
          this.setData({
            [`outTabsArr[${curTabIndex}]`]: activeTab,
          })
          // 根据实际数据设置 loadmore组件 当前状态
          activeTab.loadMoreView.loadMoreComplete({ curPage: activeTab.page, pageCount })
        }).catch(err => {
          // 加载出错 且非第一页则展示 从新加载当前页按钮
          if (activeTab.page != initPage) {
            activeTab.loadMoreView.loadMoreFail()
          }
        })
    },
  }
})